home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / pressgen / an311x.exe / JOBSERV.C < prev    next >
C/C++ Source or Header  |  1993-10-15  |  6KB  |  210 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ jobserv.c                                                                █
  5.  █                                                                          █
  6.  █ service a DOS command line job that has been put in the job queue by     █
  7.  █ doit.exe                                                                 █
  8.  █                                                                          █
  9.  ████████████████████████████████████████████████████████████████████████████
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <io.h>
  15. #include <mem.h>
  16. #include <conio.h>
  17. #include <string.h>
  18. #include <nwcalls.h>
  19. #include <nwerror.h>
  20. #include "..\doit.h"
  21.  
  22. #define NWDOS
  23.  
  24. #define ESC 0x1B
  25.  
  26. #ifndef SUCCESSFUL
  27. #define SUCCESSFUL 0x0000
  28. #endif
  29.  
  30. int            done=0,
  31.             gotone;
  32. NWCCODE             cCode;
  33. NWOBJ_ID        oID;
  34. DWORD               queueID;
  35. NWFILE_HANDLE       fileHandle;
  36. NWCONN_HANDLE        connID;
  37. char                command[181],
  38.             line[80],
  39.             ch;
  40. WORD                jobType;
  41. NWQueueJobStruct    jobStructure;
  42.  
  43. void process_job(void);
  44.  
  45. void main()
  46. {
  47.     cCode = NWCallsInit(NULL, NULL);
  48.     if (cCode == SUCCESSFUL)
  49.         printf("Call to NWCallsInit successful\n");
  50.     else {
  51.         printf("Call to NWCallsInit failed\n");
  52.         exit(-1);
  53.     }
  54.  
  55.     /* get the connection ID of the default server */
  56.     cCode = NWGetDefaultConnectionID(&connID);
  57.     if (cCode == SUCCESSFUL)
  58.         printf("Call to NWGetDefaultConnectionID successful\n");
  59.     else {
  60.         printf("Call to NWGetDefaultConnectionID failed, cCode = %X\n", cCode);
  61.         exit(-1);
  62.     }
  63.  
  64.     /* check to see if the default server has had the job server
  65.        object installed on it
  66.        If so, assume that queue directory exists, queue object was created, etc. */
  67.     cCode = NWScanObject(connID, JOBSERV_NAME, OT_DOIT, &oID, NULL, NULL, NULL, NULL, NULL);
  68.     if (cCode != SUCCESSFUL) {
  69.         printf("Job server has not been installed on this file server.\n");
  70.         exit(-1);
  71.     }
  72.  
  73.     /* log out as who you were */
  74.     cCode = NWLogoutFromFileServer(connID);
  75.     if (cCode != SUCCESSFUL) {
  76.         printf("Call to NWLogoutFromFileServer failed, cCode = %X\n", cCode);
  77.         exit(-1);
  78.     }
  79.  
  80.     /* log in as the job server object */
  81.     cCode = NWLoginToFileServer(connID, JOBSERV_NAME, OT_DOIT, JOBSERV_PWORD);
  82.     if (cCode != SUCCESSFUL) {
  83.         printf("Call to NWLoginToFileServer failed, cCode = %X\n", cCode);
  84.         exit(-1);
  85.     }
  86.  
  87.     /* get the bindery object ID of the queue we will be servicing */
  88.     cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT_Q, &queueID);
  89.     if (cCode != SUCCESSFUL) {
  90.         printf("Call to NWGetObjectID failed, cCode = %X\n", cCode);
  91.         exit(-1);
  92.     }
  93.  
  94.     /* attach to the queue we are going to service */
  95.     cCode = NWAttachQueueServerToQueue(connID, queueID);
  96.     if (cCode != SUCCESSFUL) {
  97.         printf("Call to NWAttachQueueServerToQueue failed, cCode = %X\n", cCode);
  98.         exit(-1);
  99.     }
  100.  
  101.     /* display prompt */
  102.     memset(line, '-', 79);
  103.     clrscr();
  104.     printf("Job server example program\n");
  105.     printf("Press ESC to exit\n");
  106.     gotoxy(1,5);
  107.     printf("%s\n", line);
  108.     printf("> \n");
  109.     printf("%s\n", line);
  110.  
  111.     /* continue requesting jobs from the queue until user presses ESC */
  112.     while (!(done)) {
  113.         do {
  114.             /* first, look for priority 1 */
  115.             jobType = DOIT_JOB_PRIORITY_1;
  116.  
  117.             /* see if there are any jobs to be serviced */
  118.             cCode = NWServiceQueueJob2(connID, queueID, jobType, &jobStructure, &fileHandle);
  119.             if (cCode != SUCCESSFUL) {
  120.                 jobType = DOIT_JOB_PRIORITY_2;
  121.                 cCode = NWServiceQueueJob2(connID, queueID, jobType, &jobStructure, &fileHandle);
  122.                 if (cCode != SUCCESSFUL) {
  123.                     gotoxy(1,4);
  124.                     printf("No jobs in queue");
  125.                 }
  126.             }
  127.  
  128.             /* if there is a job then process it, otherwise keep asking */
  129.             if (!(cCode)) {
  130.                 /* assume the rights of the client who submitted the job */
  131.                 cCode = NWChangeToClientRights2(connID, queueID, jobStructure.jobNumber);
  132.                 if (cCode != SUCCESSFUL) {
  133.                     printf("Call to NWChangeToClientRights2 failed, cCode = %X\n", cCode);
  134.                     exit(-1);
  135.                 }
  136.  
  137.                 /* process the job */
  138.                 process_job();
  139.  
  140.                 /* redisplay prompt */
  141.                 gotoxy(1,1);
  142.                 printf("Job server example program\n");
  143.                 printf("Press ESC to exit\n");
  144.                 gotoxy(1,5);
  145.                 printf("%s\n", line);
  146.                 printf("> \n");
  147.                 printf("%s\n", line);
  148.  
  149.                 /* clear the command string */
  150.                 memset(command,0,181);
  151.  
  152.                 /* set flag saying there is a job to service */
  153.                 gotone = 1;
  154.             }
  155.  
  156.             /* check to see if ESC has been hit */
  157.             if (kbhit()) {
  158.                 ch = getch();
  159.                 if (ch == ESC) done = 1;
  160.             }
  161.  
  162.         /* loop until done or until we have a job */
  163.         } while ((!(gotone)) && (!(done)));
  164.  
  165.         if (gotone) {
  166.             /* tell QMS we've successfully serviced the queue job */
  167.             cCode = NWFinishServicingQueueJob2(connID, queueID, jobStructure.jobNumber, fileHandle);
  168.             if (cCode != SUCCESSFUL) {
  169.                 gotoxy(1,3);
  170.                 printf("Call to NWFinishServicingQueueJob2 failed, cCode = %X", cCode);
  171.                 exit(-1);
  172.             }
  173.         }
  174.  
  175.         /* continue looking for commands */
  176.         gotone = 0;
  177.     }
  178.  
  179.     /* if the user hit ESC, then detach from the queue and logout */
  180.     /* the workstation will remain connected and default to the LOGIN directory */
  181.  
  182.     /* detach from the queue */
  183.     gotoxy(1,24);
  184.     cCode = NWDetachQueueServerFromQueue(connID, queueID);
  185.     if (cCode == SUCCESSFUL)
  186.         printf("Call to NWDetachQueueServerFromQueue successful\n");
  187.     else {
  188.         printf("Call to NWDetachQueueServerFromQueue failed, cCode = %X\n", cCode);
  189.     }
  190.  
  191.     /* logout from the file server */
  192.     cCode = NWLogoutFromFileServer(connID);
  193.     if (cCode == SUCCESSFUL)
  194.         printf("Call to NWLogoutFromFileServer successful\n");
  195.     else
  196.         printf("Call to NWLogoutFromFileServer failed, cCode = %X\n", cCode);
  197. }
  198.  
  199. void process_job(void)
  200. {
  201.     /* process the job by reading the file and sending the command to */
  202.     /* system() */
  203.     clrscr();
  204.     read(fileHandle, command, 181);
  205.     gotoxy(3,6);
  206.     printf("%s\n",command);
  207.     gotoxy(1,8);
  208.     system(command);
  209. }
  210.